import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/common/xindong_all.dart';
import 'package:xindong/common/xindong_types.dart';
import 'package:xindong/models/xindong_name_class.dart';
import 'package:xindong/utils/xindong_text_util.dart';
import 'package:xindong/widgets/common/xindong_app_bar_dialog.dart';
import 'package:xindong/widgets/common/xindong_app_bar_icon_button.dart';
import 'package:xindong/widgets/dialog/xindong_base_sheet.dart';

enum XinDongProfileSelectType {
  emotion,
  education_background,
  monthly_salary,
  occupation,
  live_status,
  is_house_purchase,
  is_car_purchase,
}

class XinDongProfileSelectSheet extends StatefulWidget {
  final String? title;
  final String? selectText;
  final XinDongProfileSelectType type;
  final Function(String text) doneCallback;

  XinDongProfileSelectSheet.show(
      {super.key, this.title, required this.selectText, required this.type, required this.doneCallback}) {
    showSmartSheet(sheet: this);
  }

  @override
  State<XinDongProfileSelectSheet> createState() => _XinDongProfileSelectSheetState();
}

class _XinDongProfileSelectSheetState extends State<XinDongProfileSelectSheet> {
  final TextStyle textStyle = const TextStyle(fontSize: 20, color: DZColors.titleColor);

  late int _currentIndex = 0;
  late final List<String> _dataList = [];
  late List<Widget> _widgetList = [];
  final _localData = {
    // 穿衣风格
    "style": [
      {"name": '黑丝'},
      {"name": '长筒袜'},
      {"name": '吊带袜'},
      {"name": '蕾丝'},
      {"name": '超短裙'},
      {"name": '雪纺裙'},
      {"name": '连衣裙'},
      {"name": '牛仔裤'},
      {"name": '萝莉'},
      {"name": '清纯'},
      {"name": '可爱'},
      {"name": '御姐'},
      {"name": '甜美'},
      {"name": '角色扮演'}
    ],
    // 语言
    "language": [
      {"name": '本地话'},
      {"name": '普通话'},
      {"name": '广东话'},
      {"name": '客家话'},
      {"name": '英语'},
      {"name": '日语'}
    ],
    // 约会节目
    "dy_program": [],
    // 约会条件 期望对象
    "dy_conditions": [],
    // 约会时间
    "dy_time": [
      {"name": '凌晨'},
      {"name": '上午'},
      {"name": '中午'},
      {"name": '下午'},
      {"name": '晚上'},
      {"name": '通宵'},
      {"name": '一整天'}
    ],
    // 职业
    "occupation": XinDongAll.instance.occupationList,
    // 星座
    "constellation": [
      {"name": "水瓶座"},
      {"name": "双鱼座"},
      {"name": "白羊座"},
      {"name": "金牛座"},
      {"name": "双子座"},
      {"name": "巨蟹座"},
      {"name": "狮子座"},
      {"name": "处女座"},
      {"name": "天秤座"},
      {"name": "天蝎座"},
      {"name": "射手座"},
      {"name": "摩羯座"}
    ],
    // 年龄
    "age": [
      {"name": "18~20岁"},
      {"name": "20~25岁"},
      {"name": "25~30岁"},
      {"name": "30~40岁"},
      {"name": "40~50岁"},
      {"name": "50岁以上"}
    ],
    // 身高
    "stature": [
      {"name": "160厘米以下"},
      {"name": "160~170厘米"},
      {"name": "170~180厘米"},
      {"name": "180~190厘米"},
      {"name": "190厘米以上"}
    ],
    // 情感状态
    "emotion": [
      {"name": "单身"},
      {"name": "恋爱中"},
      {"name": "离异"},
      {"name": "丧偶"},
      {"name": "已婚"},
      {"name": "保密"}
    ],
    // 学历
    "education_background": [
      {"name": "初中"},
      {"name": "中专"},
      {"name": "高中"},
      {"name": "大专"},
      {"name": "本科"},
      {"name": "双学士"},
      {"name": "硕士"},
      {"name": "博士"}
    ],
    // 薪资
    "monthly_salary": [
      {"name": "5万以下"},
      {"name": "5万~10万"},
      {"name": "10万~20万"},
      {"name": "20万~30万"},
      {"name": "30万~50万"},
      {"name": "50万~100万"},
      {"name": "100万以上"}
    ],
    // 居住情况
    "live_status": [
      {"name": "住自己买的房"},
      {"name": "租房自住"},
      {"name": "与人合租"},
      {"name": "住宿舍"},
      {"name": "与父母住"}
    ],
    // 是否购房
    "is_house_purchase": [
      {"name": "已购房"},
      {"name": "暂未购房"},
      {"name": "计划购房"}
    ],
    // 是否购车
    "is_car_purchase": [
      {"name": "已购车(豪华型)"},
      {"name": "已购车(中档)"},
      {"name": "已购车(经济型)"},
      {"name": "暂未购车"}
    ],
    // 语言包
    "lang_select": [
      {"name": "中文简体", "val": 'zh-CN'},
      {"name": '中國正體字', "val": 'zh-TW'},
      {"name": '한국어 공부 해요.', "val": 'ko'},
      {"name": '日本語', "val": 'ja'},
      {"name": 'بالعربية', "val": 'ar'},
      {"name": 'ViệtName', "val": 'vi'},
      {"name": 'english', "val": 'en'},
    ]
  };

  void _makeWidgetList() {
    List dataList = _localData[widget.type.name] ?? [];
    for (var object in dataList) {
      String name;
      if (object is XinDongNameClass) {
        name = object.name;
      } else {
        name = object["name"];
      }
      _dataList.add(name);
      _widgetList.add(Center(child: Text(name, style: textStyle)));
    }
  }

  @override
  void initState() {
    super.initState();
    _makeWidgetList();
    _currentIndex = _dataList.indexOf(widget.selectText ?? "");
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: DZColors.dialog,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          XinDongDialogAppBar(
            widget.title ?? "",
            leading: XinDongAppBarIconButton(onTap: () => SmartDialog.dismiss()),
            onTapDone: () {
              widget.doneCallback(_dataList[_currentIndex]);
              SmartDialog.dismiss();
            },
          ),
          SizedBox(
            height: 216 + kAppBarHeight,
            child: CupertinoPicker(
              itemExtent: 60,
              scrollController: FixedExtentScrollController(initialItem: _currentIndex),
              onSelectedItemChanged: (position) {
                _currentIndex = position;
              },
              children: _widgetList,
            ),
          ),
        ],
      ),
    );
  }
}
